1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import com.google.common.annotations.GwtCompatible;
20 import com.google.common.collect.testing.MapInterfaceTest;
21
22 import java.util.Collection;
23 import java.util.Map;
24
25
26
27
28
29
30
31
32 @GwtCompatible
33 public abstract class AbstractMultimapAsMapImplementsMapTest
34 extends MapInterfaceTest<String, Collection<Integer>> {
35
36 public AbstractMultimapAsMapImplementsMapTest(
37 boolean modifiable, boolean allowsNulls, boolean supportsIteratorRemove) {
38 super(allowsNulls, allowsNulls, false, modifiable, modifiable, supportsIteratorRemove);
39 }
40
41 protected void populate(Multimap<String, Integer> multimap) {
42 multimap.put("one", 1);
43 multimap.put("two", 2);
44 multimap.put("two", 22);
45 multimap.put("three", 3);
46 multimap.put("three", 33);
47 multimap.put("three", 333);
48 }
49
50 @Override protected String getKeyNotInPopulatedMap()
51 throws UnsupportedOperationException {
52 return "zero";
53 }
54
55 @Override protected Collection<Integer> getValueNotInPopulatedMap()
56 throws UnsupportedOperationException {
57 return Lists.newArrayList(0);
58 }
59
60
61
62
63
64
65
66
67 @Override public void testRemove() {
68 final Map<String, Collection<Integer>> map;
69 final String keyToRemove;
70 try {
71 map = makePopulatedMap();
72 } catch (UnsupportedOperationException e) {
73 return;
74 }
75 keyToRemove = map.keySet().iterator().next();
76 if (supportsRemove) {
77 int initialSize = map.size();
78 map.get(keyToRemove);
79 map.remove(keyToRemove);
80
81
82 assertFalse(map.containsKey(keyToRemove));
83 assertEquals(initialSize - 1, map.size());
84 } else {
85 try {
86 map.remove(keyToRemove);
87 fail("Expected UnsupportedOperationException.");
88 } catch (UnsupportedOperationException e) {
89
90 }
91 }
92 assertInvariants(map);
93 }
94 }